package tasks.leetcode;

public class TaskSearchInsert {
    public static void main(String[] args) {

    }
    public int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length;
        int mid = left + (right - left) / 2;
        while (left < right) {
            if (nums[mid] < target) {
                left = mid + 1;
            } else if (nums[mid] > target) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return mid;
    }
}
